package com.java.service;

import com.java.dao.StoresMapper;
import com.java.pojo.Page;
import com.java.pojo.Stores;
import com.java.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("SService")
public class StoresServiceImpl implements StoresService {
    @Autowired
    private StoresMapper storesMapper;


    @Override
    public List<Stores> getStoresList() {
        return storesMapper.getStoresList();
    }

    @Override
    public Page<Stores> getPageByStores(Integer a, String username) {
        int b=4;//显示条数
        Page<Stores> page=new Page<>();
        page.setCurryPage(a);//设置当前页码
        page.setRows(b);//设置每页显示的条数
        Integer count = storesMapper.getCountStores(username);//总条数
        page.setTotalCount(count);//总条数
        int start=(a-1)*b;/*开始的索引*/
        List<Stores> list = storesMapper.getListStores(start, b, username);
        page.setList(list);/*赋值list*/
        int totalPae=count % b==0 ? count / b : (count / b)+1;
        page.setTotalPae(totalPae);/*设置总页数*/
        if(page==null){
            page=null;
        }
        return page;
    }

    @Override
    public Integer getCountStores(String username) {
        return storesMapper.getCountStores(username);
    }

    @Override
    public int addStores(Stores stores) {
        Stores stByName = storesMapper.getStByName(stores.getSname());
        if(stByName==null) {
            return storesMapper.addStores(stores);
        }else {
            return 0;
        }
    }

    @Override
    public int delSt(Integer id) {
        return storesMapper.delSt(id);
    }

    @Override
    public List<Stores> getStList() {
        return storesMapper.getStList();
    }

    @Override
    public Stores getStByName(String a) {
        return storesMapper.getStByName(a);
    }
}
